var BSTMG = BSTMG || {};
BSTMG.userDealListManager = {
	init: function(){
		var that = this;
		//分页功能
		that.selectUserDealList();
	},
	selectUserDealList: function(){
		var userId = $('#userId').val();
		BSTMG.common.hjhPages("/sysAdmin/accountMoney/userDealList",{userId:userId},function(data){
			var dealList = data.dealList;
			var $tbody = $("#userDealList tbody");
			var $tr = '';
			if(dealList.length > 0) {
				for(var i=0;i<dealList.length;i++){
					var userInfo = dealList[i];
					var dealState = setDealState(userInfo);
					var dealMoney = setDealMoney(userInfo);
					var payWayId = setPayWayId(userInfo);
					$tr += '<tr class="odd">';
					$tr += '<td>'+(i+1)+'</td>';
					$tr += '<td>'+BSTMG.tools.checkNull(userInfo.dealName)+'</td>';
					$tr += '<td>'+BSTMG.tools.checkNull(dealState)+'</td>';
					$tr += '<td>'+parseFloat(dealMoney).toFixed(2)+'</td>';
					$tr += '<td>'+BSTMG.tools.checkNull(payWayId)+'</td>';
					$tr += '<td><a type="button" class="btn btn-primary" href="/sysAdmin/accountMoney/userDealDetail/'+userInfo.dealId+'">交易详情</a></td>';
					$tr += '</tr>';
				}
				$tbody.html($tr);
			}else {
				var $tr = '<tr class="odd"><td colspan="6">暂无数据！</td></tr>';
				$tbody.html($tr);
			}
		});
	}
}

$(function(){
	BSTMG.userDealListManager.init();
});
//设置交易状态
function setDealState(userInfo){
	if(userInfo.dealState == 1){
		return "充值";
	}else if(userInfo.dealState == 2){
		return "消费";
	}else if(userInfo.dealState == 3){
		return "提现";
	}else if(userInfo.dealState == 4){
		return "退款";
	}else if(userInfo.dealState == 0){
		return "交易失败";
	}else{
		return "";
	}
}
//设置交易金额
function setDealMoney(userInfo){
	if(userInfo.dealState == 1||userInfo.dealState == 4){
		return userInfo.incomeMoney;
	}else if(userInfo.dealState == 2||userInfo.dealState == 3){
		return userInfo.disburseMoney;
	}else{
		return 0.00;
	}
}
//设置支付方式
function setPayWayId(userInfo){
	if(userInfo.payWayId == 1){
		return "支付宝支付";
	}else if(userInfo.payWayId == 2){
		return "账户余额支付";
	}else if(userInfo.payWayId == 3){
		return "银联支付";
	}else if(userInfo.payWayId == 4){
		return "线下支付";
	}else{
		return "";
	}
}

